package com.idopartx.phonelightning.utils

import android.content.Context

object PreferenceSetting {

    const val PREFS_FILE = "tools_config"
    const val IS_FIRST = "is_first" //是否第一次进入
    private val SHOW_SPLASH_LIMIT_TIME = "ShowSplashLimitTime"//闪屏间隔
    private val SHOW_THUMBUP = "show_thumbup"
    private val LAST_RUN_TIME = "last_runtime"
    private val SHOW_THUMB_UP_ED = "show_thumb_up_ed"

    //第一次进入
    fun isFirst(context: Context): Boolean {
        val preferences = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        return preferences.getBoolean(IS_FIRST, true)
    }

    fun setFirst(context: Context, b: Boolean) {
        val preferences = context.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        preferences.edit().putBoolean(IS_FIRST, b).apply()
    }

    /**
     * 记录闪屏时间间隔 单位秒
     */
    fun saveShowSplashLimitTime(cxt: Context, time: Int) {
        val preferences = cxt.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        preferences.edit().putInt(SHOW_SPLASH_LIMIT_TIME, time).apply()
    }

    fun getShowSplashLimitTime(cxt: Context): Int {
        val prefs = cxt.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        return prefs.getInt(SHOW_SPLASH_LIMIT_TIME, 1)
    }

    /**
     * 是否需要显示好评
     */
    fun getShowThumbUp(cxt: Context): Boolean {
        val prefs = cxt.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        return prefs.getBoolean(SHOW_THUMBUP, false)
    }

    /**
     * 是否需要显示好评
     */
    fun setShowThumbUp(cxt: Context, isShow: Boolean) {
        val preferences = cxt.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        preferences.edit().putBoolean(SHOW_THUMBUP, isShow).apply()

    }

    /**
     * 记录显示好评弹窗的时间
     */
    fun saveLastRunTime(cxt: Context, time: Long) {
        val preferences = cxt.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        preferences.edit().putLong(LAST_RUN_TIME, time).apply()
    }

    fun getLastRunTime(cxt: Context): Long {
        val prefs = cxt.getSharedPreferences(PREFS_FILE,  Context.MODE_PRIVATE)
        return prefs.getLong(LAST_RUN_TIME, 0)
    }

    /**
     * 是否显示过好评
     */
    fun getShowThumbUped(cxt: Context): Boolean {
        val prefs = cxt.getSharedPreferences(PREFS_FILE,  Context.MODE_PRIVATE)
        return prefs.getBoolean(SHOW_THUMB_UP_ED, false)
    }

    fun setShowThumbUped( cxt: Context,isShow: Boolean) {
        val preferences = cxt.getSharedPreferences(PREFS_FILE, Context.MODE_PRIVATE)
        preferences.edit().putBoolean(SHOW_THUMB_UP_ED, isShow).apply()
    }
}